package org.jground.rx.ui.zk;

import java.util.ArrayList;
import java.util.List;

import org.jground.rx.IRXAccess;
import org.jground.rx.RXAccess;
import org.jground.rx.RXPage;
import org.jground.rx.RXView;
import org.jground.rx.ui.IUIAttribute;
import org.jground.rx.ui.pref.FocusData;
import org.jground.rx.ui.zk.viewControl.UIAttributeFactory;
import org.jground.util.CollectionUtils;
import org.jground.zk.zulX.TableX;
import org.zkoss.zk.ui.Component;

public class UIPage {

    private RXPage rxPage;

    private List<IUIAttribute<Component, UIFrame>> uiLocalAttributes = new ArrayList<IUIAttribute<Component, UIFrame>>();
    // private DivX uiPage = new DivX();
    private TableX labelControlPanel;

    // private GridX labelControlPanel = new GridX("100px", "80%");

    public UIPage(UIFrame uiFrame, RXPage rxPage, List<IUIAttribute<Component, UIFrame>> uiAttributes) {
        this.rxPage = rxPage;
        IRXAccess rxAccess = RXAccess.getInstance();
        labelControlPanel = new TableX("vertical-align: top; padding-left:4px; padding-right:4px;background-color: #ecedef;white-space:nowrap;border: #ecedef 1px dotted;border-right:solid 3px #ecedef;", "width:95%;border: #ecedef 1px dotted");
        labelControlPanel.setStyle("width:100%;border: red dotted 0px");
        //
        List<RXView> rxViews = rxPage.getEnabledRXViewControls();
        for (RXView rxView : rxViews) {
            if (rxAccess.isEntitled(rxView)) {
                IUIAttribute<Component, UIFrame> uiAttribute = UIAttributeFactory.create(uiFrame, rxView);
                labelControlPanel.addRow(uiAttribute.getLabelComponent(), uiAttribute.getControlComponent());
                CollectionUtils.addUnique(uiAttributes, uiAttribute);
                uiLocalAttributes.add(uiAttribute);
            }
        }
    }

    public RXPage getRXPage() {
        return rxPage;
    }

    // public String getLabel() {
    // return rxPage.getLabel();
    // }

    public Component getView() {

        return labelControlPanel;
    }

    public boolean isEmpty() {
        return uiLocalAttributes.size() == 0;
    }

    public FocusData getFocusData() {
        FocusData fd = new FocusData();
        return fd;
    }

    public void setFocusData(FocusData fd) {

    }

}